<template>
	<div class="aps">
		<top-bar title="审批详情">
			<div slot="rightItem"></div>
		</top-bar>
		<div class="aps-title">{{this.$route.query.text}}</div>
		<!-- 表单 -->
		<type-data ref="types" v-for="item in arrList" :types="item"></type-data>
		<!-- 备注 -->
		<div class="remarks">
			<van-field v-model="message" rows="5" label="备注" show-word-limit type="textarea" maxlength="512" />
		</div>
		<type-data ref="types2" :types="myFile"></type-data>
		<div class="bnt">
			<button style="background-color: #5CCA99;color: #FFFFFF;" type="button" @click="submit">确定</button>
			<button style="background-color: #EEEEEE;color: #A19FA0;" type="button" @click="back">取消</button>
		</div>
		<div class="seat"></div>
	</div>
</template>

<script>
	import typeData from '@components/assembly.vue'
	import topBar from '@components/topBar.vue'
	import {
		getForm2
	} from '@request/api.js'
	import {
		getField
	} from '@request/api.js'
	import {submit} from '@assets/js/submit.js'
	export default {
		data() {
			return {
				arrList: [],
				message: '',
				bntText: '',
				myFile: {
					name: '附件',
					fieldType: "92",
					fieldDataGroupDataLists: [],
					fieldEventLists: [],
					fieldName: 'fixed'
				}
			}
		},
		components: {
			topBar,
			typeData
		},
		methods: {
			back() {
				this.$router.back()
			},
			getRequest(isTrue,obj) {
				if (isTrue) {
					// console.log(obj,"通过！")
					this.$axios.post(
						`/api/processWorkFlow?_form=${this.$route.query.form_id}&_num=${this.$route.query.num}&_btn=${this.$route.query.bnt}`,
						obj).then(res => {
						if (res.data.code == 0) {
							this.$toast.success(`${this.bntText}成功`)
							if (this.$route.query.status == 'approval') {
								this.$router.push('/user/approval')
							} else {
								if(this.$route.query.bnt === 'btn7'){
									this.$router.push('/applyuser/complete')
								}else{
									this.$router.push('/applyuser/apply')
								}								
							}
						}
					})
				}
			},
			submit(values) { 
				const arr = submit(this.$refs.types)	
				const isTrue = arr[0]
				const obj = arr[1]
				//添加附件
				let a_file = this.$refs.types2.pushData().fixed
				if (a_file.constructor !== Object)
					this.$set(obj, "_attach", a_file)
				// 添加备注
				this.$set(obj, "_comment", this.message)
				this.$set(obj, "_currentTime", this.$route.query.currentTime)
				if (this.$route.query.bnt !== 'btn6' && this.$route.query.bnt !== 'btn7') {
					this.getRequest(isTrue,obj)
				} else {
					// console.log(this.message)
					if (this.message !== '') {
						this.getRequest(isTrue,obj)
					} else {
						this.$toast(this.$store.state.allColor.rejection_text)
					}
				}
			}
		},
		created() {
			if (this.$route.query.text == '通过') {
				this.bntText = "审批"
			} else {
				this.bntText = this.$route.query.text
			}
			if (this.$route.query.bnt === 'btn2' || this.$route.query.bnt === 'btn5') {
				getField({
					'_form': this.$route.query.form_id,
					'_num': this.$route.query.num,
					'_type': 'changeWorkFlow'
				}).then(res => {
					// console.log(res, '总表')
					if (res.code == 0) {
						this.arrList = res.fieldMapLists['无']
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.aps {
		background-color: $bg-1;
	}

	.aps-title {
		font-size: vw(16);
		font-weight: 550;
		color: $color1;
		background-color: #FFFFFF;
		border-bottom: 1px solid $line-1;
		padding: vw(23) 0 vw(12) 16px;
	}

	.bnt {
		display: flex;
		flex-direction: row-reverse;
		flex-wrap: wrap;
		align-items: center;
		position: fixed;
		bottom: 0;
		left: 0;
		height: vw(60);
		width: 100vw;
		background-color: $bg-1;
		z-index: 3;
	}

	.bnt button {
		padding: vw(5) vw(32);
		font-size: vw(14);
		border: none;
		outline: none;
		margin-right: 16px;
	}

	.seat {
		height: vw(60);
		width: 100vw;
		background-color: #FFFFFF;
	}

	.remarks {
		margin-top: vw(15);
		border-bottom: 1px solid $line-1;

		/deep/ .van-field__label {
			width: 3em;
		}
	}

	.van-uploader {
		/deep/ .van-uploader__upload {
			width: vw(76);
			height: vw(76);
		}

		/deep/ .van-uploader__preview-image {
			width: vw(76);
			height: vw(76);
		}
	}
</style>
